package ldh.im.server.file.initialize;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

public class FileChannelInitializer extends ChannelInitializer<SocketChannel> {

    private static final int MAX_LENGTH = 1024 * 256;

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new IdleStateHandler(2,5,7, TimeUnit.MINUTES));
        pipeline.addLast(new LengthFieldBasedFrameDecoder(MAX_LENGTH, 0, 2));
    }
}
